package home.my.base.web;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts2.ServletActionContext;
import org.apache.struts2.json.annotations.JSON;

import com.opensymphony.xwork2.ActionContext;

public abstract class BaseAction{
	//获取request,response,session方式一，非IoC方式，不用实现SessionAware, ServletRequestAware, ServletResponseAware  
    private ActionContext context = ActionContext.getContext();
    public String msg;
    
    //为了配合struts的json插件此方法需要最终实现action子类来实现
    public String getMsg(){
    	return msg;
    }
    
    @JSON(serialize=false)
    public ActionContext getContext(){
    	return context;
    }
    
    @JSON(serialize=false)
    public HttpServletRequest getRequest(){
    	return (HttpServletRequest) context.get(ServletActionContext.HTTP_REQUEST);
    }
    
    @JSON(serialize=false)
    public HttpServletResponse getResponse(){
    	return (HttpServletResponse) context.get(ServletActionContext.HTTP_RESPONSE);
    }
    
    @JSON(serialize=false)
    public Map<String, Object> getSession(){
    	return context.getSession();
    }
    
    @JSON(serialize=false)
    public Map<String, Object> getApplication(){
    	return context.getApplication();
    }
    
}
